#include<stdio.h>
#include<stdlib.h>
#include<memory.h>

int m=7,n=6;
int *A,*B;
int **table;

void dp()
{
    int i,j;
    for(i=0;i<=m;i++)
        for(j=0;j<n;j++)
        {
            if(i==0 && j==0)
                continue;
            if(A[i]==B[j] &&
               i>0 && j>0 &&
               (table[i-1][j-1]+1)>table[i][j])
               {
                   table[i][j]=table[i-1][j-1]+1;
               }
            if(A[i]!=B[j] &&
               i>0  &&
               (table[i-1][j]+1)>table[i][j])
               {
                   table[i][j]=table[i-1][j]+1;
               }
            if(A[i]==B[j] &&
               j>0 &&
               (table[i][j-1]+1)>table[i][j])
               {
                   table[i][j]=table[i][j-1]+1;
               }
        }
}

int main()
{
    int C[]={1,2,3,2,4,1,2};
    int D[]={2,4,3,1,2,1};
    A=C,B=D;

    table=malloc(sizeof(int*)*(m+1));
    int i;
    for(i=0; i<=m; i++)
    {
        table[i]=malloc(sizeof(int)*(n+1));
        memset(table[i],0,sizeof(int)*(n+1));
    }

    dp();

    printf("%d",table[m][n]);

}
